package dao;

import java.sql.SQLException;
import java.text.SimpleDateFormat;

import model.Return;
import util.DBUtil;

public class ReturnDAO {
	public boolean save(Return ret){
		DBUtil util = new DBUtil("insert into `return` values(?,?,?,?,?,?,?)");
		try {
			util.pst.setString(1, ret.getRejectId());
			util.pst.setString(2, ret.getRejectCode());
			util.pst.setString(3, ret.getQuantity()+"");
			util.pst.setString(4, ret.getReason());
			util.pst.setString(5, ret.getCreator());
			util.pst.setString(6, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(ret.getTs()));
			util.pst.setString(7, ret.getProductId());
			util.pst.execute();
			util.close();
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
			util.close();
			return false;
		}
	}
	public boolean updateCodeAndCreator(String code,String creator,String id){
		DBUtil util = new DBUtil("update `return` set `REJECT _CODE` = ?, CREATOR = ? where REJECT_ID = ?");
		try {
			util.pst.setString(1, code);
			util.pst.setString(2, creator);
			util.pst.setString(3, id);
			util.pst.execute();
			util.close();
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
			util.close();
			return false;
		}
	}
}
